/*
 * @Author: 马思宁 598138645@qq.com
 * @Date: 2024-04-08 09:54:25
 * @LastEditors: 马思宁 598138645@qq.com
 * @LastEditTime: 2024-05-09 18:13:22
 * @FilePath: \v-koa\src\controller\login.controller.js
 * @Description: 
 */
const jwt = require("jsonwebtoken");
const { PRIVATE_KEY } = require("../config/screct");

class LoginController {
  async sign(ctx, next) {
    // 1.获取用户信息
    const { id, name } = ctx.user;

    // 2.颁发令牌token
    const token = await jwt.sign({ id, name }, PRIVATE_KEY, {
      expiresIn: 24 * 60 * 60, // 有效时间
      algorithm: "RS256",
    });

    // 3.返回用户信息
    ctx.body = { code: 200, msg: "操作成功", token: token };
  }
  test(ctx, next) {
    ctx.body = { code: 0, data: "验证身份通过~" };
  }
}

module.exports = new LoginController();
